******************************************
* Documentation for Andersson, K., Chang, K., Molina-Garzón, A.
* "Voluntary Leadership and the Emergence of Institutions for Self-Governance"

* Data: Andersson, K.P., Magnuszewski, P., Pajak, M., Salk, C.F., Stefanska, J., Wright, G.D. 2020. “Forest Rules” Game Data for 16 groups of forest users in Bolivia and Uganda. 
* Dataverse DOI link: 
use "ForestrulesDat080920", clear

saveold ForestrulesDat080920_old, version(12) replace

* I. Descriptive statistics
*Summary statistics
summarize RulesAgree LeaderAny LeaderUnself LeaderSelf SpeakersNum ///
StockDect2 Round LeaderOlder LeaderMale LeaderMoreedu LeaderWealthy 

*Distribution of DV over round by groups
twoway scatter RulesAgree Round, ylabel(0(0.5)1) ytitle("DV: Rule agreement") ///
xtitle("Round #") by(SessId,  note("") caption("") subtitle("") ///
title("")) scheme(s1mono) 

graph export "DVoverround.png", replace

* II. Main models (Table 1) 
* Model 1: without interaction terms, Group fixed effect
xtset SessId Round

xtreg RulesAgree LeaderUnself LeaderSelf ///
StockDect2 SpeakersNum LeadersNum Round , fe vce(cluster SessId)
est store m1

* Model 2: with interaction terms, Group fixed effect
xtreg RulesAgree LeaderUnself LeaderSelf ///
StockDect2 SpeakersNum LeadersNum Round ///
c.LeaderUnself#c.StockDect2 c.LeaderUnself#c.SpeakersNum, fe vce(cluster SessId)
est store m2


* Model 3: with interaction terms and leader demographics, Group fixed effect
xtreg RulesAgree LeaderUnself LeaderSelf ///
StockDect2 SpeakersNum LeadersNum Round LeaderOlder LeaderMale LeaderMoreedu LeaderWealthy  ///
c.LeaderUnself#c.StockDect2 c.LeaderUnself#c.SpeakersNum, fe vce(cluster SessId)
est store m3

* Table 1:
esttab m1 m2 m3, ///
b(%9.2f) t(%9.2f) r2(%9.2f) star(* 0.1 ** 0.05 *** 0.01) ///
cells(b(star label(Coef.) fmt(2)) se(par fmt(2))) ///
stats(N r2 aic bic rmse, labels("N. of cases" ))
 
* Marginal effects (Figure 2) 
est restore m2
margins, dydx(LeaderUnself) at (StockDect2 = (0(1)7) SpeakersNum=(1))
marginsplot, ///
	 graphregion(color(white))	///
	 ci1opts(recast(rline) fintensity(15) lpattern(dash_3dot)) ///
	 recast(line) ///
	 yline(0, lpattern(dash)	/// 
	 lwidth(vvthin) lcolor(black))	/// 
	 ylabel( , angle(0) nogrid)	/// 
	 xtitle("Decreased # of rows in past 2 rounds)")	///
    ytitle("ME of unselfish leadership")	/// 
	 title("(a) Over forest stock decrease")	/// 
	 xlabel(0(1)7)	/// 
	 xscale (r(0(1)7)) ///
	 legend(off)	/// 
	 saving (lex_stockdec1, replace)

margins, dydx(LeaderUnself) at (SpeakersNum=(0(1)8) StockDect2=(0))
marginsplot, ///
	 graphregion(color(white))	/// 
	 ci1opts(recast(rline) fintensity(15) lpattern(dash_3dot)) /// 
	 recast(line) ///
	 yline(0, lpattern(dash)	/// 
	 lwidth(vvthin) lcolor(black))	/// 
	 ylabel( , angle(0) nogrid)	/// 
	 xtitle("# of Speakers in current round")	/// 
	 ytitle("ME of unselfish leadership")	/// 
	 title("(b) Over level of discussion ")	/// 
	 xlabel(0(1)8)	///
	 xscale (r(0(1)8)) ///
	 legend(off)	/// 
	 saving (lex_speak1, replace)
	 
graph combine lex_stockdec1.gph lex_speak1.gph, r(1) ycommon ///
graphregion(color(white)) ///
note("Note:(a) At no discussion (Speaker number = 1); (b) At no stock decrease")
graph export melexam_simp080920.png, replace
graph export melexam_simp080920.png, replace

